package com.yan.furns.dao.impl;

import com.yan.furns.dao.BasicDAO;
import com.yan.furns.dao.OrderDAO;
import com.yan.furns.entity.Order;

import java.util.List;

/**
 * @author Yzb
 * @version 1.0
 */
public class OrderDAOImpl extends BasicDAO<Order> implements OrderDAO {

	@Override
	public int saveOrder(Order order) {
		String sql = "insert into `order` (`id`, `create_time`, `price`, `status`, " +
				"`member_id`) values (?,?,?,?,?)";
		return update(sql, order.getId(), order.getCreateTime(), order.getPrice(), order.getStatus(), order.getMemberId());
	}

	@Override
	public List<Order> getOrdersByMemberId(int memberId) {
		String sql = "select `id`, `create_time`, price, `status`, `member_id` memberId from `order` where `member_id` = ?";
		return queryMulti(sql, Order.class, memberId);
	}

	@Override
	public Order getOrderByOrderId(String orderId) {
		String sql = "select `id`, `create_time`, price, `status`, `member_id` memberId from `order` where `id` = ?";
		return querySingle(sql, Order.class, orderId);
	}
}
